package com.gitee.wsl.doc.prosemirror.model.node.ext

import com.gitee.wsl.doc.prosemirror.model.node.Node

fun Node.contentBetween(from: Int, to: Int): Boolean {
    val doc = this
    val resolvedFrom = doc.resolve(from)
    var dist = to - from
    var depth = resolvedFrom.depth
    while (dist > 0 && depth > 0 && resolvedFrom.indexAfter(depth) == resolvedFrom.node(depth).childCount) {
        depth--
        dist--
    }
    if (dist > 0) {
        var next = resolvedFrom.node(depth).maybeChild(resolvedFrom.indexAfter(depth))
        while (dist > 0) {
            if (next == null || next.isLeaf) return true
            next = next.firstChild
            dist--
        }
    }
    return false
}